#include <signal.h>
#include <stdio.h>
#include "Mem.h"
#include "ExampleException.h"

static ExampleExceptionVirtualTable* ExampleExceptionVirtualTableInstance;

ExampleException* ExampleExceptionNew(unsigned long pArgsCount, va_list* pParameters)
{
    ExampleException* this;
    this = (ExampleException*) malloc(sizeof(ExampleException));
    if(!this)
    {
        raise(SIGABRT);
    }
    this->VirtualTable = ExampleExceptionInitialize(this, pArgsCount, pParameters);
    this->Constructor = ExampleExceptionConstructor;
    this->Destructor = ExampleExceptionDestructor;
    this->Clone = ExampleExceptionClone;
    this->PreviousException = (const Exception* const (*)(ExampleException*))this->VirtualTable->AncestorTable->Interface->PreviousException;
    this->Message = (const String* const (*)(ExampleException*))this->VirtualTable->AncestorTable->Interface->Message;
    this->Example = ExampleExceptionExample;
    this->Constructor(this, pArgsCount, pParameters);
    return this;
}

ExampleExceptionVirtualTable* ExampleExceptionInitialize(ExampleException* this, unsigned long pArgsCount, va_list* pParameters)
{
    if(!ExampleExceptionVirtualTableInstance)
    {
        ExampleExceptionVirtualTableInstance = (ExampleExceptionVirtualTable*) malloc(sizeof(ExampleExceptionVirtualTable));

        if(!ExampleExceptionVirtualTableInstance)
        {
            raise(SIGABRT);
        }
        ExampleExceptionVirtualTableInstance->TypeID = EXAMPLEEXCEPTION_TYPEID;

        ExampleExceptionVirtualTableInstance->Interface = 0;

        ExampleExceptionVirtualTableInstance->AncestorTable = ExceptionInitialize((Exception*)this, pArgsCount, pParameters);

        ExampleExceptionVirtualTableInstance->ReferenceCount = 0;

        ExampleExceptionVirtualTableInstance->new = ExampleExceptionNew;
        ExampleExceptionVirtualTableInstance->Initialize = ExampleExceptionInitialize;
        ExampleExceptionVirtualTableInstance->Garbage = (void (*)(ExampleException*))ExampleExceptionVirtualTableInstance->AncestorTable->Garbage;
        ExampleExceptionVirtualTableInstance->TypeOf = (unsigned long int (*)(ExampleException*))ExampleExceptionVirtualTableInstance->AncestorTable->TypeOf;
        ExampleExceptionVirtualTableInstance->IsSameTypeThanTypeID = (bool (*)(ExampleException*, unsigned long int))ExampleExceptionVirtualTableInstance->AncestorTable->IsSameTypeThanTypeID;
        ExampleExceptionVirtualTableInstance->IsKindOfTypeID = (bool (*)(ExampleException* this, unsigned long int))ExampleExceptionVirtualTableInstance->AncestorTable->IsKindOfTypeID;
        ExampleExceptionVirtualTableInstance->IsSameTypeThan = (bool (*)(ExampleException* this, Class*))ExampleExceptionVirtualTableInstance->AncestorTable->IsSameTypeThan;
        ExampleExceptionVirtualTableInstance->IsKindOf = (bool (*)(ExampleException* this, Class*))ExampleExceptionVirtualTableInstance->AncestorTable->IsKindOf;
    }
    ExampleExceptionVirtualTableInstance->ReferenceCount++;
    return ExampleExceptionVirtualTableInstance;
}

void ExampleExceptionConstructor(ExampleException* this, unsigned long int pArgsCount, va_list* pParameters)
{
    if(pArgsCount > 1)
    {
        this->aExample = va_arg(*pParameters, bool);
    }
    else
    {
        this->aExample = false;
    }
}

void ExampleExceptionDestructor(ExampleException* this)
{

}

ExampleException* ExampleExceptionClone(ExampleException* this)
{
    return (ExampleException*) new((void*(*)(unsigned long int, va_list*))ExampleExceptionNew,3,this->Message(this)->CharPointer((String*)this->Message(this),(char*)0), this->PreviousException(this), this->aExample);
}

void ExampleExceptionExample(ExampleException* this)
{
    printf("\nExampleException is = ");
    if(!this->aExample)
	{
		printf("False\n");
	}
	else
	{
		printf("True\n");
	}
	this->aExample = !this->aExample;
}
